# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=extremetuxracer
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.4
pkgrel=1
pkgdesc="Downhill racing game starring Tux (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://sourceforge.net/projects/extremetuxracer"
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-sfml"
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
source=("https://downloads.sourceforge.net/${_realname}/etr-${pkgver}.tar.xz"
        "0001-relocate.patch"
        "pathtools.c"
        "pathtools.h")
sha256sums=('fa3285cc0c755a5aff529f3f2cea3516481114c6b4b8e1ec0769feeff04773e5'
            'dfe6fa9c5ac538545dca8c734fb10f79e9d1a44440c44c1f22227c7289cbc67b'
            'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0'
            '1585ef1b61cf53a2ca27049c11d49e0834683dfda798f03547761375df482a90')

prepare() {
  test ! -d "${startdir}/../mingw-w64-pathtools" || {
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.c" "${srcdir}/pathtools.c" &&
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.h" "${srcdir}/pathtools.h"
  } || exit 1

  cd etr-${pkgver}
  cp -fHv "${srcdir}"/pathtools.[ch] src/
  patch -p1 -i "${srcdir}/0001-relocate.patch"
  ./autogen.sh
}

build() {
  cd "${srcdir}/etr-${pkgver}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../"etr-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}"

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make DESTDIR="${pkgdir}" install
}
